package huawei0814;
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
/**
 * Created by JiaJia on 2019/8/30 0030.
 */
public class XiaoMing {




/** 请完成下面这个函数，实现题目要求的功能 **/
        /** 当然，你也可以不按照这个模板来作答，完全按照自己的想法来 ^-^  **/
        static String getIndexAndLongest(String users,int k) {

            StringBuilder sb=new StringBuilder();
            if (users==null||users.length()<=1){
                return users;
            }
            int start=0,end=0;
            int max=Integer.MIN_VALUE;
            int index=0,length=0;
            for (int i = 0; i <users.length(); i++) {
                if (users.charAt(i)=='b'){
                    length=find(users,i-1,i+1);
                }
                if (length>max){
                    max=length;
                    index=i;
                }
            }
            sb.append(index).append(" ");
            StringBuilder sb2=new StringBuilder(users);
            sb2.append(users);
            String str=sb.toString();
            char[] arr=str.toCharArray();
            int res=getMax(arr,k);
            sb.append(res);


            return sb.toString();
        }
        private static int find(String s,int left,int right){
            while (left>=0&&right<=s.length()&&(s.charAt(left)=='g'||s.charAt(right)=='g')){
                if (s.charAt(left)=='g'){
                    left--;
                }
                if (s.charAt(right)=='b'){
                    right++;
                }
            }
            return right-left-2;
        }
        private static int getMax(char[] arr,int k){
            int left=0,result=Integer.MIN_VALUE;
            int count=0;
            for (int right = 0; right <arr.length ; right++) {
                if (arr[right]=='g'){
                    count++;
                }
                while (count==k){
                    if (arr[left]=='g'){
                        k--;
                    }
                    left++;
                }
                result=Math.max(result,right-left+1);
            }
            return result;
        }

        public static void main(String[] args){
            Scanner in = new Scanner(System.in);
            String res;
            int k;
            String _users;
            try {
                _users = in.nextLine();
                 k=in.nextInt();
            } catch (Exception e) {
                _users = null;

            }

            //res = getIndexAndLongest(_users,k);
            //System.out.println(res);
        }
    }
